package com.tanhua.server.exceptions;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class BasicExceptionAdvice {


    @ExceptionHandler(TanhuaException.class)  //当controller中的方法出现TanhuaException这个异常时就会进入到这个方法
    public ResponseEntity tanhuaExceptionHandler(TanhuaException e){
        e.printStackTrace();
        System.out.println("进入到了BasicExceptionAdvice的tanhuaExceptionHandler方法");
        return ResponseEntity.status(e.getStatusCode()).body(e.getMessage());
    }

    @ExceptionHandler(Exception.class)  //当controller中的方法出现Exception这个异常时就会进入到这个方法
    public ResponseEntity exceptionHandler(Exception e){
        e.printStackTrace();
        System.out.println("进入到了BasicExceptionAdvice的exceptionHandler方法");
        return ResponseEntity.status(500).body(e.getMessage());
    }

}
